<template>
  <div class="big_box">
    <img v-if="isWechat" src="../../assets/image/isWechat.jpg" alt="">
    <div v-else class="login_big_box">
      <div class="login_top_box">
      <div class="logo_image_box">
        <div class="logo_image">
          <img src="../../assets/image/chezhu_logo.png" alt="">
        </div>
      </div>
      <div class="logo_text_box">
        <div class="logo_text">
          未注册的用户自动注册新账号
        </div>
      </div>
      </div>
      <div class="login_bottom_box">
      <div class="login_input_box">
        <van-field class="login_input" v-model="inputPhoneNumber" placeholder="请输入手机号" size="large" type='tel' @blur="checkPhoneNumber" :maxlength='11' />
      </div>
      <div class="login_check_box">
        <div class="check_box">
          <van-checkbox
            v-model="isChecked"
            checked-color="#F6C401"
            icon-size="16px"
          />
          <div style="margin-left:6px;">
            <span>已阅读并同意
              <span href="" 
              @click="goUserAgreement"
              style="color:#F6C401;"
              >《用户注册协议》</span>
              和
              <span href="" 
              @click="goPrivacyPolicy"
              style="color:#F6C401;"
              >《隐私政策》</span>
            </span>
            </div>
        </div>
      </div>
      <div class="login_btn_box">
        <div class="btn_box">
          <van-button type="primary" size="large" :disabled="!isChecked" @click="getVerificationCode">获取验证码</van-button>
        </div>
      </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant'
import { validPhone } from "../../common/validate";
import { getUserAppAcquireWeChat } from './api'

export default {
  data() {
    return {
      inputPhoneNumber:'',
      isChecked:false,
      isWechat:true
    }
  },
  methods: {
    // 失焦校验手机号码
    checkPhoneNumber(){
      if (!validPhone(this.inputPhoneNumber)) {
        Toast("手机号码格式错误，请重新输入！");
      }
    },
    // 用户协议
    goUserAgreement(){
      this.$router.push({
        name:'userAgreementNew'
      })
    },
    // 跳转意思政策页面
    goPrivacyPolicy(){
      this.$router.push({
        name:'privacyAgreeNew'
      })
    },
    // 获取验证码
    async getVerificationCode(){
      if (this.inputPhoneNumber == '') return Toast('请输入手机号码')
      let params = {
        mobile:this.inputPhoneNumber,
        type:1
      }
      const data = await getUserAppAcquireWeChat(params)
      if (data.code !== 0) return Toast(data.msg)
      let id = this.$route.query.id
      this.$router.push({
        name:'verificationCode',
        query:{
          id,
          phoneNumber:this.inputPhoneNumber
        }
      })
    },
    // 判断当前环境
    getEnvironment() {
      //判断当前环境（微信/其他）
      let ua = navigator.userAgent.toLowerCase();
      if (ua.match(/MicroMessenger/i) == "micromessenger") {
        console.log("微信中");
        this.isWechat = true
      } else {
        console.log("其他（浏览器等等）");
        this.isWechat = false
      }
    },
  },
  created() {
    document.title = "用户登录";
    this.getEnvironment()
  },
}
</script>

<style lang="less" scoped>
.big_box{
  width: 100vw;
  height: 100vh;
  background-color: #fff;
  img{
    width: 100%;
    height: 100%;
  }
  .login_big_box{
    width: 100vw;
    height: 100vh;
    background-color: #fff;
    .login_top_box{
      height: 140px;
      .logo_image_box{
        padding: 40px 0 16px 30px;
        .logo_image{
          width: 80px;
          height: 36px;
          img{
            width: 100%;
            height: 100%;
          }
        }
      }
      .logo_text_box{
        padding-left: 30px;
        .logo_text{
          height: 17px;
          font-size: 12px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #666666;
          line-height: 17px;
        }
      }
    }
    .login_bottom_box{
      .login_input_box{
        font-size: 18px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #B3B3B3;
        display: flex;
        justify-content: center;
        .login_input{
          width: 90vw;
          border-bottom:1px solid #B3B3B3;
        }
      }
      .login_check_box{
        height: 77px;
        display: flex;
        justify-content: center;
        align-items: center;
        .check_box{
          width: 90vw;
          height: 17px;
          font-size: 12px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #999999;
          line-height: 17px;
          display: flex;
        }
      }
      .login_btn_box{
        display: flex;
        justify-content: center;
        .btn_box{
          width: 90vw;
          height: 25px;
          font-size: 18px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #B3B3B3;
          line-height: 25px;
        }
      }
    }
  }

}
</style>